package work.huangxin.share.service.impl;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.bouncycastle.asn1.ocsp.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import work.huangxin.share.domain.delivery.DeliveryInfo;
import work.huangxin.share.domain.sechand.SechandBuyGoods;
import work.huangxin.share.mapper.DeliveryInfoMapper;
import work.huangxin.share.service.DeliveryInfoService;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * (deliveryInfo) 服务实现类
 *
 * @author 张锦标
 * @since 2023-04-24 21:29:51
 */
@Service
public class DeliveryInfoServiceImpl implements DeliveryInfoService {

    @Autowired
    private DeliveryInfoMapper deliveryInfoMapper;

    @Override
    public DeliveryInfo selectDeliveryInfoById(Long deliveryInfoId) {
        return deliveryInfoMapper.selectById(deliveryInfoId);
    }

    @Override
    public long insertDeliveryInfo(DeliveryInfo deliveryInfo) {
        long id = deliveryInfoMapper.insert(deliveryInfo);
        return id;
    }

    @Override
    public PageInfo<DeliveryInfo> selectDeliveryInfoPage(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        Page<DeliveryInfo> deliveryInfoList = deliveryInfoMapper
                .selectPageDeliveryInfoList();
        return PageInfo.of(deliveryInfoList);
    }

    @Override
    public boolean updateDeliveryInfo(DeliveryInfo deliveryInfo) {
        if (Objects.isNull(deliveryInfo)) {
            throw new RuntimeException("前端传来的对象为空");
        }
        int isUpdate = deliveryInfoMapper.updateById(deliveryInfo);
        if (isUpdate == 0) {
            throw new RuntimeException("修改任务失败,可能是id不存在");
        }
        return isUpdate > 0;
    }

    @Override
    public boolean deleteDeliveryInfo(List<Long> deliveryInfoIds) {
        for (Long id : deliveryInfoIds) {
            int i = deliveryInfoMapper.deleteById(id);
            if (i==0){
                throw new RuntimeException("删除失败");
            }
        }
        return true;
    }


}

